import { del, get, post } from "@/utils/request";


interface PMemoryDay {
    id?: number;
    type?: number;
    title?: string;
    targetTime?: string; // 对应 Java 的 LocalDateTime 类型
}

interface MemoryDayVo extends PMemoryDay{
    firstDays: number;
    nextDays: number;
}

// 新增
const memoryDayAdd = async (day: PMemoryDay) => {
    try {
        return await post<any>("/memoryDay/add/", day)
    } catch (error) {
        console.error("纪念日查询操作出现问题: ", error);
    }
}
// 修改
const memoryDayUpdate = async (day: PMemoryDay) => {
    try {
        return await post<any>("/memoryDay/update/", day)
    } catch (error) {
        console.error("纪念日修改操作出现问题: ", error);
    }
}
// 删除
const memoryDayDel = async (dayId: number) => {
    try {
        return await del<any>("/memoryDay/delete/" + dayId)
    } catch (error) {
        console.error("纪念日删除操作出现问题: ", error);
    }
}

// 基于类型查询, 0-公历, 1-农历
const memoryDayListByType = async (type: number) => {
    try {
        return await get<MemoryDayVo[]>("/memoryDay/listByType/" + type)
    } catch (error) {
        console.error("纪念日基于类型查询操作出现问题: ", error);
    }
}

// TODO 基于日期查询
 interface  AllDayVo extends PMemoryDay{
    isMemoryDay: boolean;
}
const memoryDayListByDate = async (calendar: string, lunar: string) => {
    try {
        return await get<AllDayVo[]>(`/memoryDay/listByDay?lunar=${lunar}&calendar=${calendar}`)
    } catch (error) {
        console.error("基于日期查询纪念日和倒计日操作出现问题: ", error);
    }
}

export{
    memoryDayListByType,
    memoryDayDel,
    memoryDayUpdate,
    memoryDayAdd,
    memoryDayListByDate,
}
